<!DOCTYPE html>
<html class="x-admin-sm">
  
  <head>
    <meta charset="UTF-8">
    <title>修改用户信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script type="text/javascript" src="./js/cookie.js"></script>
    
  </head>
  
  <body>
    <div class="x-body">
        <div class="layui-form">
          <div class="layui-form-item">
              <label for="L_email" class="layui-form-label">
                  <span class="x-red">*</span>用户名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="username"  required="" lay-verify="email"
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>将会成为您唯一的登入名
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_username" class="layui-form-label">
                  <span class="x-red">*</span>密码
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="password"  required="" lay-verify="nikename"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" id="xg_btn">
                修改
              </button>
          </div>
      </div>
    </div>
    <script src="js/main.js"></script>
        <script>
    
     $(function(){
    	 get_user_info();
     });
    
     function get_user_info(){
         var url = window.location;
         var id = getUrlParam(url,"id");
         $.ajax({
             url:"/lvyou/SeluserByIdServlet",
             type:"post",
             data:"id="+id,
             success:function(data){
            	 console.log(JSON.parse(data));
             	if(JSON.parse(data).code==100){
             		$("#username").val(JSON.parse(data).extend.user.username);
             		$("#password").val(JSON.parse(data).extend.user.password);
             		
             	}else if(result.code==200){
             	    				  
             	}
             }
         });
     } 
      //获取url地址上参数
        function getUrlParam(url,name){
             var pattern = new RegExp("[?&]" + name +"\=([^&]+)","g");
             var matcher = pattern.exec(url);
             var items = null;
             if(matcher != null){
                  try{
                      items = decodeURIComponent(decodeURIComponent(matcher[1]));   
                  }catch(e){
                      try{
                          items = decodeURIComponent(matcher[1]);
                  }catch(e){
                          items = matcher[1];
                       }
                  }
              }
              return items;
        }
      
      $("#xg_btn").click(function(){
    	   
           var url = window.location;
           var id = getUrlParam(url,"id");
           var username = $("#username").val();
           var password = $("#password").val();
             $.ajax({
                 url:"/lvyou/UpuserServlet",
                 type:"post",
                 data:"id="+id+"&username="+username+"&password="+password,
                 success:function(data){
                	 console.log(JSON.parse(data));
		  			  if(JSON.parse(data).code==100){
		  				showMessage('修改成功','success',1000)
		  			  }else{
		  				showMessage('修改失败','error',1000)
		  			  }
                  }
             });
      });
    </script>
        
  </body>

</html>